package com.csw.scala

import scala.io.{BufferedSource, Source}

object Demo22StudentsWordCount {
  def main(args: Array[String]): Unit = {

    //1、读取文件
    val students: List[String] = Source.fromFile("Scala/data/students.txt").getLines().toList

    //2、取出班级
    val classs: List[String] = students.map(line => line.split(",")(4))

    //3、对班级进行分组
    val clazzs: Map[String, List[String]] = classs.groupBy(clazz => clazz)
//    clazzs.foreach(kv =>println(kv))

    //4、求各个班级个数
    val wordcount = clazzs.map(kv =>{
      val clazz: String = kv._1
      val count: Int = kv._2.length

      (clazz,count)
    })
    wordcount.foreach(println)
  }
}
